#include <cstdio>
#include <queue>

using namespace std;

priority_queue<int, vector<int>, greater<int>> queue_data;

int main(int argc, char const* argv[])
{
    int n;
    while (scanf("%d", &n) != EOF) {
        int cost;
        while (!queue_data.empty())
            queue_data.pop();
        for (int i = 0; i < n; i++) {
            scanf("%d", &cost);
            queue_data.push(cost);
        }
        int result = 0;
        while(queue_data.size() > 1){
            int a = queue_data.top();
            queue_data.pop();
            int b = queue_data.top();
            queue_data.pop();
            int c = a + b;
            queue_data.push(c);
            result += c;
        }
        printf("%d\n", result);
    }

    return 0;
}